from myClass.spiders import BaiDuBar as bd
from myClass.spiders import DouBan as db
from myClass.spiders import DYTT
from myClass.spiders import DyttNew
import math
import json


def json_study():
    """
    json介绍
    :return:
    """
    # json_content = None
    # 1. 读取json文件
    with open('student.json', 'r', encoding='utf-8') as f:
        json_content = f.read()
        # print(json_content)
        # 将json类型的字符串转换成python对象(字典对象)
        p_object = json.loads(json_content)
        print(type(p_object))
        print(p_object)
        # 提取女朋友的名字
        # 遍历
        for stu in p_object["students"]:
            for girl in stu["girl_friends"]:
                print(girl["name"])


if __name__ == "__main__":
    # 1. 百度贴吧爬虫
    # bd("美女").run()

    # # 2. 豆瓣电影/电视剧爬虫
    # # 2.1 先获取tag
    # db.get_tags(db.tv_tag_url)
    # db.get_tags(db.movie_tag_url)
    #
    # # 2.2 创建豆瓣爬虫对象
    # d = db(tag=db.tag["movie"][0], t="movie")
    # # 2.3 启动爬虫程序
    # d.run()
    # # 2.3 显示图示
    # rates = []
    # names = []
    # for f in d.sources:
    #     rates.append(float(f["评分"]))
    #     names.append(f["电影名"])
    #
    # # 显示线性图, 折线图
    # # d.show_line(x=names, y=rates, end=20)
    #
    # # print(rates)
    # # 显示条形图, 柱状图
    # d.show_bar(x=names, y=rates, end=20)
    #
    # # print(math.ceil(3.4))
    # # print(math.floor(4.6))
    #

    # 3.电影天堂二级解析
    # DYTT().run(2)

# 4.电影天堂协程版
    DyttNew().run(3)
